package 字符串算法;

public class 左旋转字符串 {
    class Solution{
        public String reverseLeftWords(String s,int n){
            int len = s.length();
            StringBuilder sb = new StringBuilder();
            reverseString(sb,0,n-1);
            reverseString(sb,n,len-1);
            //StringBuilder自带的reverse是实现倒序的
            //各自区间倒过来后就整体倒过来
            return sb.reverse().toString();


        }

        private void reverseString(StringBuilder sb,int start, int end) {
            while (start<end) {
                char temp = sb.charAt(start);
                sb.setCharAt(start, sb.charAt(end));
                sb.setCharAt(end, temp);
                start++;
                end--;
            }
        }
    }
}
